package com.wangsh.splider.outer.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.annotation.Resource;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wangsh.splider.common.pojo.ApiResponse;
import com.wangsh.splider.common.pojo.ApiResponseEnum;
import com.wangsh.splider.common.service.BaseServiceImpl;
import com.wangsh.splider.common.util.ConstatFinalUtil;
import com.wangsh.splider.common.util.ExecutorServiceUtil;
import com.wangsh.splider.common.util.PageInfoUtil;
import com.wangsh.splider.orders.pojo.AOrdersClient;
import com.wangsh.splider.orders.pojo.AOrdersUsers;
import com.wangsh.splider.orders.pojo.AOrdersUsersEnum;
import com.wangsh.splider.orders.service.IOrdersDbService;
import com.wangsh.splider.outer.IServerOuterService;
import com.wangsh.splider.system.pojo.ASysClient;
import com.wangsh.splider.system.pojo.ASysClientEnum;
import com.wangsh.splider.system.pojo.ASysCountry;
import com.wangsh.splider.system.pojo.ASysIp;
import com.wangsh.splider.system.pojo.ASysProxy;
import com.wangsh.splider.system.pojo.ASysWebUrl;
import com.wangsh.splider.system.pojo.ASysWebUrlEnum;
import com.wangsh.splider.system.service.ISystemOperService;
import com.wangsh.splider.system.service.ISystemDbService;
import com.wangsh.splider.task.pojo.ATaskUsers;
import com.wangsh.splider.task.service.ITaskDbService;
import com.wangsh.splider.util.ServiceCallableUtil;

/**
 * 用户不需要登陆的一些操作
 * 
 * @author wangsh
 * @param <T>
 */
@Service("serverOuterService")
public class ServerOuterServiceImpl<T> extends BaseServiceImpl implements IServerOuterService
{
	@Resource
	private ISystemDbService systemDbService;

	@Resource
	private ISystemOperService systemOperService;

	@Resource
	private IOrdersDbService ordersDbService;

	@Resource
	private IOrdersDbService orderService;

	@Resource
	private ITaskDbService taskDbService;

	/**
	 * 验证加密的字符串
	 * 
	 * 加密参数;sha256(version+pubKey+私钥)
	 * 
	 * @return
	 */
	private ApiResponse<Object> verifyEncryptStr(JSONObject reqJSON)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		String version = reqJSON.getString("version");
		String pubKey = reqJSON.getString("pubKey");
		String encryptStr = reqJSON.getString("encrypt");

		/*
		 * 为了安全,私钥不能从请求中获取,读取本地的配置文件 私钥:客户端和服务器端同时存储到配置文件中
		 */
		// priKey=abc
		String priKey = ConstatFinalUtil.CONFIG_JSON.getString("private.key");

		String encHou = DigestUtils.sha256Hex(version + pubKey + priKey);
		if (encHou.equalsIgnoreCase(encryptStr)
				|| "0".equalsIgnoreCase(ConstatFinalUtil.CONFIG_JSON.getString("version")))
		{
			/* 成功 */
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			/* 请求非法,您在恶意攻击 */
			apiResponse.setCode(ApiResponseEnum.INFO_JSON_ATTACK.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> serverVersionService(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--clientVersionService--");
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		String version = reqJSON.getString("version");
		String method = reqJSON.getString("method");
		if ("WebUrlList".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.webUrlList(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("WebUrlInfo".equalsIgnoreCase(method))
		{

			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.WebUrlInfo(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}

		} else if ("WebUrlUpdate".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.WebUrlUpdate(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("judgeClientStatus".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.judgeClientStatus(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("orderUserList".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.orderUserList(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("batchInsert".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.batchInsert(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("sysCountryList".equalsIgnoreCase(method))
		{
			apiResponse = this.sysCountryList(reqJSON);
		} else
		{
			apiResponse.setCode(ApiResponseEnum.INFO_METHOD_ERROR.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 提示信息 */
		return apiResponse;
	}

	/**
	 * 返回一个显示WebUrl的列表
	 * 
	 * @param reqJSON
	 * @return
	 */
	public ApiResponse<Object> webUrlList(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--WebUrlList--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		// 进入到list代表访问的客户端已经开始攻击了,然后获取客户端的信息
		JSONObject clientJson = reqJSON.getJSONObject("clientInfo");
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);

		// 接收参数
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		// 设置分页 就是为了限制条数 随机获取10条记录
		PageInfoUtil pageInfoUtil = new PageInfoUtil();
		Integer pageSize = dataReqJSON.getInteger("pageSize");
		Integer currentPage = dataReqJSON.getInteger("currentPage");
		// 写死的 获取10条记录
		pageInfoUtil.setPageSize(pageSize);
		pageInfoUtil.setCurrentPage(currentPage);
		Map<String, Object> condMap = new HashMap<String, Object>();
		// 按照pubTime排序
		condMap.put("pubtimeAsc", "pubtimeAsc");
		condMap.put("status", ASysWebUrlEnum.STATUS_ENABLE.getStatus());
		ApiResponse<ASysWebUrl> WebUrlListApi = systemDbService.findCondListWebUrlService(pageInfoUtil, condMap);
		List<ASysWebUrl> WebUrlList = WebUrlListApi.getDataListJava();
		if (WebUrlList != null)
		{
			// 接收获取到的集合
			Map<String, List<Object>> dataList = new HashMap<String, List<Object>>();
			List<Object> value = new ArrayList<Object>();

			for (int i = 0; i < WebUrlList.size(); i++)
			{
				ASysWebUrl webUrl = WebUrlList.get(i);
				// 获取pojo转为json
				JSONObject dataArryJSON = webUrl.toJSON();
				value.add(dataArryJSON);

				/* 启用多线程 */
				ServiceCallableUtil serviceCallableUtil = new ServiceCallableUtil();
				Map<String, Object> paramsMap = new HashMap<String, Object>();
				paramsMap.put("webUrl", webUrl);
				paramsMap.put("systemService", systemDbService);

				/* 调用多线程 */
				serviceCallableUtil.setOperType("updateWebUrl");
				serviceCallableUtil.setParamsMap(paramsMap);
				ExecutorServiceUtil.submit(serviceCallableUtil);
			}
			dataList.put(ApiResponseEnum.NAME_LIST.getName(), value);
			apiResponse.setPageInfoUtil(WebUrlListApi.getPageInfoUtil());
			apiResponse.setDataList(dataList);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{

			apiResponse.setCode(ApiResponseEnum.INFO_LOGIN_ILLEGAL.getStatus());
		}

		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 存储client数据 */
		JSONObject dataCliJSON = (JSONObject) clientJson.get("data");
		if (dataCliJSON == null)
		{
			dataCliJSON = new JSONObject();
		}
		/* 增加服务端类型 */
		dataCliJSON.put("clientType", dataReqJSON.get("clientType"));
		clientJson.put("data", dataCliJSON);
		systemOperService.operSaveClient(clientJson);
		/* 提示信息 */
		return apiResponse;
	}

	/**
	 * 返回一个显示WebUrl的详情
	 * 
	 * @param reqJSON
	 * @return
	 */
	public ApiResponse<Object> WebUrlInfo(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--WebUrlList--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}

		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);
		// 接收参数
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		int id = Integer.valueOf(dataReqJSON.get("id") + "");

		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		ApiResponse<ASysWebUrl> WebUrlInfo = systemDbService.findOneWebUrlService(condMap);

		if (WebUrlInfo.getDataOne() != null)
		{
			ASysWebUrl WebUrl = WebUrlInfo.getDataOneJava();
			Map<String, Object> dataOne = new HashMap<String, Object>();
			JSONObject info = WebUrl.toJSON();
			dataOne.put(ApiResponseEnum.NAME_ONE.getName(), info);
			// 返回的信息
			apiResponse.setDataOne(dataOne);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.INFO_LOGIN_ILLEGAL.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 提示信息 */
		return apiResponse;
	}

	/**
	 * WebUrl的更新
	 * 
	 * @param reqJSON
	 * @return
	 */
	public ApiResponse<Object> WebUrlUpdate(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--WebUrlUpdate--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}

		// 进入到update代表访问的客户端已经返回结果了就把成功次数和失败次数存进去
		JSONObject clientJson = reqJSON.getJSONObject("clientInfo");
		// 存储client的成功次数以及失败次数
		JSONObject data = new JSONObject();
		// client的成功次数以及失败次数
		int totalNum = 1;
		int todayTotalNum = 1;
		int succedNum = 0;
		int failedNum = 0;
		int todaySuccedNum = 0;
		int todayFailedNum = 0;
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);
		systemOperService.operJudgeClinetStatus();
		// 接收参数
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		int id = Integer.valueOf(dataReqJSON.get("id") + "");
		int failedCount = Integer.valueOf(dataReqJSON.get("failedCount") + "");
		int succedCount = Integer.valueOf(dataReqJSON.get("succedCount") + "");
		int totalCount = Integer.valueOf(dataReqJSON.get("totalCount") + "");
		String response = dataReqJSON.getString("response");
		JSONObject responseHeaderJson = dataReqJSON.getJSONObject("responseHeader");
		JSONArray responseHeader = new JSONArray();
		responseHeaderJson.entrySet();
		for (Entry<String, Object> entry : responseHeaderJson.entrySet())
		{
			JSONObject jsonOb = new JSONObject();
			jsonOb.put(entry.getKey(), entry.getValue());
			responseHeader.add(jsonOb);
		}
		Map<String, Object> condMap = new HashMap<String, Object>();
		// 存储id 先查出要更新的表
		condMap.put("id", id);
		ApiResponse<ASysWebUrl> WebUrlApi = systemDbService.findOneWebUrlService(condMap);
		ASysWebUrl WebUrl = WebUrlApi.getDataOneJava();
		// 设置要存储的值
		WebUrl.setFailedCount(WebUrl.getFailedCount() + failedCount);
		WebUrl.setSuccedCount(WebUrl.getSuccedCount() + succedCount);
//		WebUrl.setTotalCount(WebUrl.getTotalCount() + totalCount);
		WebUrl.setResponse(response);
		WebUrl.setResponseHeader(responseHeader + "");
		// 保存结果
		ApiResponse<Object> updateOneWebUrlService = systemDbService.updateOneWebUrlService(WebUrl);
		if (updateOneWebUrlService.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			succedNum++;
			todaySuccedNum++;
		} else
		{
			apiResponse.setCode(ApiResponseEnum.INFO_LOGIN_ILLEGAL.getStatus());
			failedNum++;
			todayFailedNum++;
		}
		// 为data设置设置值
		data.put("totalNum", totalNum);
		data.put("todayTotalNum", todayTotalNum);
		data.put("succedNum", succedNum);
		data.put("todaySuccedNum", todaySuccedNum);
		data.put("failedNum", failedNum);
		data.put("todayFailedNum", todayFailedNum);
		clientJson.put("data", data);
		systemOperService.operSaveClient(clientJson);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 提示信息 */
		return apiResponse;
	}

	/**
	 * 更新client的状态
	 * 
	 * @param reqJSON
	 * @return
	 */
	public ApiResponse<Object> judgeClientStatus(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--judgeClientStatus--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}

		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);
		// 接收参数
		JSONObject clientJson = (JSONObject) reqJSON.get("clientInfo");
		// 获取ip
		String ip = clientJson.get("ip").toString();
		if ("0:0:0:0:0:0:0".equalsIgnoreCase(ip.trim()) || ip == null || "".equals(ip))
		{
			ip = "127.0.0.1";
		}
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("ip", ip);
		ApiResponse<ASysIp> sysIpApi = systemDbService.findOneSysIpService(condMap);
		int ipId = 0;
		int countryId = 0;
		// 如果为null 代表 ip表中没有这个ip 就保存
		if (sysIpApi.getDataOneJava() == null)
		{
			// 查询ip在数据库中是否存在和所属国家
			ApiResponse<ASysIp> operFindIp = this.systemOperService.operFindIp(ip);
			if (operFindIp.getDataOneJava() == null)
			{
				return new ApiResponse<Object>();
			}
			ipId = operFindIp.getDataOneJava().getId();
			countryId = operFindIp.getDataOneJava().getCountryId();
		} else
		{
			// 如果不为null 酒吧ipId已存 然后去看client表中是否存在有这个ipId的client就好
			ipId = sysIpApi.getDataOneJava().getId();
			countryId = sysIpApi.getDataOneJava().getCountryId();
		}
		condMap.clear();
		condMap.put("ipId", ipId);
		ApiResponse<ASysClient> sysClientApi = systemDbService.findOneClientService(condMap);
		if (sysClientApi.getDataOneJava() != null)
		{
			ASysClient sysClient = sysClientApi.getDataOneJava();
			sysClient.setStatus(ASysClientEnum.STATUS_ATTACKING.getStatus());
			sysClient.setAttackTime(new Date());
			ApiResponse<Object> updateOneClientService = systemDbService.updateOneClientService(sysClient);
			Map<String, Object> dataOne = new HashMap<String, Object>();
			dataOne.put(ApiResponseEnum.NAME_ONE.getName(), sysClient.toJSON());
			// 判断保存结果是否为成功
			if (updateOneClientService.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());

			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setDataOne(dataOne);
			;
			// 返回的信息
		} else
		{
			apiResponse.setCode(ApiResponseEnum.INFO_LOGIN_ILLEGAL.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 提示信息 */
		return apiResponse;
	}

	/*
	 * 返回一个显示orderUserList的列表
	 */
	public ApiResponse<Object> orderUserList(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--orderUserList--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);

		// 接收参数
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		// 设置分页信息，具体在上行json中设置
		PageInfoUtil pageInfoUtil = new PageInfoUtil();
		Integer pageSize = dataReqJSON.getInteger("pageSize");
		Integer currentPage = dataReqJSON.getInteger("currentPage");
		pageInfoUtil.setPageSize(pageSize);
		pageInfoUtil.setCurrentPage(currentPage);
		Map<String, Object> condMap = new HashMap<String, Object>();
		// 查询orderUser表的所有记录
		ApiResponse<AOrdersUsers> findCondListUsersService = ordersDbService.findCondListUsersService(pageInfoUtil,
				condMap);
		List<AOrdersUsers> ordersUserList = findCondListUsersService.getDataListJava();
		if (ordersUserList != null)
		{
			// 接收获取到的集合
			Map<String, List<Object>> dataList = new HashMap<String, List<Object>>();
			List<Object> value = new ArrayList<Object>();

			for (int i = 0; i < ordersUserList.size(); i++)
			{
				AOrdersUsers orderUsers = ordersUserList.get(i);
				// 获取pojo转为json
				JSONObject dataArryJSON = orderUsers.toJSON();
				value.add(dataArryJSON);

			}
			// 储存响应信息
			dataList.put(ApiResponseEnum.NAME_LIST.getName(), value);
			apiResponse.setPageInfoUtil(findCondListUsersService.getPageInfoUtil());
			apiResponse.setDataList(dataList);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{

			apiResponse.setCode(ApiResponseEnum.INFO_LOGIN_ILLEGAL.getStatus());
		}

		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 提示信息 */
		return apiResponse;
	}

	public ApiResponse<Object> batchInsert(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--batchInsert--");
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		JSONArray userList = reqJSON.getJSONArray("data");
		Map<String, Object> condMap = new HashMap<String, Object>();
		for (int i = 0; i < userList.size(); i++)
		{
			JSONObject first = JSON.parseObject(userList.get(i) + "");
			try
			{
				/* facebook返回的信息  */
				String responseCode = first.getString("responseCode");
				String responseInfo = first.getString("responseInfo");
				String cookieFini = first.getString("cookieFini");
				String cookieTarget = first.getString("cookieTarget") ; 
				String souType = first.getString("souType") ; 
				
				// new对象 为对象赋值
				condMap.clear();
				// 根据Email看是否能查询到结果，如果不为null代表该Email已被添加
				condMap.put("email", first.getString("email"));
				ApiResponse<AOrdersUsers> ordersUsersResponse = orderService.findOneUsersService(condMap);
				/* true:表示肯定要更新;false:表示要添加 */
				boolean updateFlag = true ; 
				AOrdersUsers ordersUsers = ordersUsersResponse.getDataOneJava();
				if (ordersUsers == null )
				{
					ordersUsers = new AOrdersUsers() ; 
					ordersUsers.setEmail(first.getString("email"));
					ordersUsers.setCreateTime(new Date());
					updateFlag = false ; 
				}
				// 根据已知字段值查该记录的ID
				ApiResponse<ASysIp> findOneSysIpService = systemOperService.operFindIp(first.getString("ip"));
				// 木有查到不赋值，该字段为默认值。
				ASysIp sysIp = findOneSysIpService.getDataOneJava();
				if (sysIp != null)
				{
					ordersUsers.setSysIpId(sysIp.getId());
				} else
				{

				}
				if (first.getString("cookieTarget") != null && !"".equals(first.getString("cookieTarget")))
				{
					condMap.clear();
					condMap.put("cookieTarget", first.getString("cookieTarget"));
					ApiResponse<AOrdersClient> findOneClientService = orderService.findOneClientService(condMap);
					AOrdersClient dataOneJava = findOneClientService.getDataOneJava();
					if (dataOneJava != null)
					{
						ordersUsers.setClientId(dataOneJava.getId());
					}
					condMap.clear();
				}
				condMap.put("email", first.getString("email"));
				ApiResponse<ATaskUsers> findOneUsersService = taskDbService.findOneUsersService(condMap);
				ATaskUsers taskUsers = findOneUsersService.getDataOneJava();
				if (taskUsers != null)
				{
					ordersUsers.setUsersId(taskUsers.getId());
				}
				if (ordersUsers.getSysIpId() != 0)
				{
					condMap.clear();
					condMap.put("ipId", ordersUsers.getSysIpId());
					ApiResponse<ASysProxy> findOneSysProxyService = systemDbService.findOneSysProxyService(condMap);
					ASysProxy sysProxy = findOneSysProxyService.getDataOneJava();
					if (sysProxy != null)
					{
						ordersUsers.setSysProxyId(sysProxy.getId());
					}
				}
				ordersUsers.setPhone(first.getString("phone"));
				ordersUsers.setPassword(first.getString("password"));
				/* 设置Cookie */
				ordersUsers.setCookieTarget(cookieTarget);
				ordersUsers.setCookieFini(cookieFini);
				ordersUsers.setHttpSource(first.getString("httpSource"));
				/* 状态不对 */
				if(ApiResponseEnum.INFO_LOGIN_SUCCES.getStatus() == Byte.valueOf(responseCode)
					|| 
					ApiResponseEnum.INFO_COOKIE_SUCCESS.getStatus() == Byte.valueOf(responseCode))
				{
					ordersUsers.setStatus(AOrdersUsersEnum.STATUS_VERIFY.getStatus());
					/* 把整个上行信息都存储下来;如果cookie成功,那就都保留下来 */
					ordersUsers.setContent(first.toJSONString());
				}else
				{
					ordersUsers.setStatus(AOrdersUsersEnum.STATUS_INVALID.getStatus());
					/* 原来的数据;如果失败了,只存储状态和信息 */
					JSONObject contentJSON = ordersUsers.getContentJSON() ;
					contentJSON.put("responseCode", responseCode);
					contentJSON.put("responseInfo", responseInfo);
					ordersUsers.setContent(contentJSON.toJSONString());
				}
				if(souType != null && !"".equalsIgnoreCase(souType))
				{
					/* 来源都是购买 */
					ordersUsers.setSouType(Byte.valueOf(souType));
				}else
				{
					ordersUsers.setSouType(AOrdersUsersEnum.SOUTYPE_BUY.getStatus());
				}
				
				ordersUsers.setUpdateTime(new Date());
				ordersUsers.setPubTime(new Date());
				
				if(updateFlag)
				{
					/* faceBook登陆成功时,更新
					 * 数据库的记录为失败更新
					 *  */
					/* 更新 */
					apiResponse = this.orderService.updateOneUsersService(ordersUsers);
				}else
				{
					/* 添加 */
					apiResponse = orderService.saveOneUsersService(ordersUsers);
				}
			} catch (Exception e)
			{
				ConstatFinalUtil.SYS_LOGGER.error("处理上传数据时失败了;数据:{}",first,e);
			}
		}
		return apiResponse;
	}

	/*
	 * 返回一个显示国家列表
	 */
	public ApiResponse<Object> sysCountryList(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--orderUserList--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);

		// 接收参数
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		Map<String, Object> condMap = new HashMap<String, Object>();
		// 查询orderUser表的所有记录
		ApiResponse<ASysCountry> sysCountryApi = systemDbService.findCondListCountryService(null, condMap);
		List<ASysCountry> sysCountryList = sysCountryApi.getDataListJava();
		if (sysCountryList != null)
		{
			// 接收获取到的集合
			Map<String, List<Object>> dataList = new HashMap<String, List<Object>>();
			List<Object> value = new ArrayList<Object>();

			for (int i = 0; i < sysCountryList.size(); i++)
			{
				ASysCountry sysCountry = sysCountryList.get(i);
				// 获取pojo转为json
				JSONObject dataArryJSON = sysCountry.toJSON();
				value.add(dataArryJSON);
			}
			// 储存响应信息
			dataList.put(ApiResponseEnum.NAME_LIST.getName(), value);
			apiResponse.setDataList(dataList);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{

			apiResponse.setCode(ApiResponseEnum.INFO_LOGIN_ILLEGAL.getStatus());
		}

		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 提示信息 */
		return apiResponse;
	}
}
